import { createRouter, createWebHashHistory } from 'vue-router'

import store from "@/store"
import login from "@/components/login";
import home from "@/components/home";
import user from "@/views/user/user";
import person from "@/views/person/person";
import makePhy from "@/views/phy/makePhy";
import phyTaocan from "@/views/phy/phyTaocan"
import phyAdmin from "@/views/phy/phyAdmin";
import archives from "@/views/archives/archives";
import programme from "@/views/programme/programme";
import medicine from "@/views/programme/medicine";
import record from "@/views/record/record";
import index_data from "@/components/index/index_data";
import analysis from "@/views/analysis/analysis";
import jkyj from "@/views/jkyj/jkyj";
import jkpg from "@/views/jkpg/jkpg";

const routes = [
  {
    path:'/',
    redirect:'/login',
  },
  {
    name:'登录',
    path: '/login',
    component:login,
  },
  {
    name:'首页',
    path:'/home',
    component:home,
    children:[
      {
        name:'用户中心',
        path:'/sys_user',
        component:user,
      },
      {
        name:'个人中心',
        path:'/person',
        component:person,
      },
      {
        name:'体检套餐',
        path:'/phy_taocan',
        component:phyTaocan,
      },
      {
        name:'体检预约',
        path:'/phy_center',
        component:makePhy,
      },
      {
        name:'预约管理',
        path:'/make',
        component:phyAdmin,
      },
      {
        name:'健康档案管理',
        path:'/archives',
        component:archives,
      },
      {
        name:'饮食方案设计',
        path:'/programme',
        component:programme,
      },
      {
        name:'药物使用方案设计',
        path:'/statistics',
        component:medicine,
      },
      {
        name:'我的健康日志',
        path:'/my_logs',
        component:record,
      },
      {
        name:'数据统计',
        path:'/index_datav',
        component:index_data,
      },
      {
        name:'健康分析',
        path:'/health_analysis',
        component:analysis,
      },
      {
        name:'健康预警',
        path:'/jkyj',
        component:jkyj,
      },
      {
        name:'健康评估',
        path:'/jkpg',
        component:jkpg,
      }

    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach(((to, from, next) => {
  localStorage.setItem("currentPathName", to.name) //设置当前的路由名称
  store.commit("setPath") //触发store的数据更新
  next() //放行路由
}))

export default router
